package jdbc;

import util.DBUtil;

import java.sql.*;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Fenye2 {
    //不推荐
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("一页多少条：");
        int pageSize = in.nextInt();
        System.out.println("查看第几页：");
        int pageNo = in.nextInt();

        String sql = "select * from s_student order by stuno desc";
        Connection connection = DBUtil.get();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            //设置结果集可滚动
            ps = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ps.setMaxRows(pageNo * pageSize);//最多取多少
            rs = ps.executeQuery();
            rs.absolute((pageNo - 1) * pageSize);//跳过前面的
            while (rs.next()) {
                System.out.println(rs.getLong("stuno"));
                System.out.println(rs.getString("sname"));
                Date enterdate = rs.getDate("enterdate");
                System.out.println("入学时间：" + enterdate);
                System.out.println(">>>>>>>>>>>>>>>>>>>");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, ps, connection);
        }
    }
}
